package me.zhengjie.util;


import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class UuidUtil {

    public static Long genUuid() {
        /**
         * Allen Gao
         * 记录用法
         */
//        Date d = new Date();
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String dateNowStr = sdf.format(d);
        /**
         * end
         */

        String date = new SimpleDateFormat("yyMMdd").format(new Date());
        String uuid1 = date + getFour();
        Long uuid = Long.parseLong(uuid1);
        return uuid;
    }

    public static String getFour() {
        Random random = new Random();
        int result = random.nextInt(10000);
        String newResult = String.format("%0" + 4 + "d", result);
        return newResult;
    }

    public static String genCode() {
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
        String dateNowStr = sdf.format(d);
        String[] chars = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
        String res = "";
        for (int i = 0; i < 4; i++) {
            int id = (int) Math.ceil(Math.random() * 35);
            res += chars[id];
        }
        return dateNowStr + res;
    }
}
